web: safely handle immutable globals #779 #780
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See #779
Though this looks a bit ugly, it beats the alternative.
Explanation:
JavaScript doesn't support checking directly whether a
Global
object is mutable or not, and parsing enough WASM to determine if each global is mutable requires being able to parse WASM expressions, meaning all possible opcodes permitted in initialization and their parameters. I gave it a quick attempt still, but the amount of opcodes that you have support depends on WASM extensions (e.g. globals using reference types and vector types add more opcodes you need to be able to handle in expressions), and simply adding the ones available today doesn't feel future-proof.I'm also fine with reverting the global patching completely, though it would be a bit unfortunate.
Another alternative is using a proper WASM parsing library, but that increases bundle size instead, and would still need updating if a new WASM extension is ever made.
The
DEV_NETPLAY
addition is for it to use thehttp://localhost:3000/?netplay=xyz
URL rather than wasm4.org when enabled, which eliminated some domain issues I was having otherwise. I figured I'll look into that issue in a separate PR.